package school;

/**
 * @author: jack
 * @date: 2018/10/27 13:3518
 * @version: 0.1
 * @description: <建立Course类，重载equals方法>
 * @modified: <修改说明>
 **/
public class Course {
    private String id;
    private String name;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getame() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Course(String id, String name) {
        this.id = id;
        this.name = name;
    }

    //如果有子类继承，必须手写无参构造函数
    public Course() {

    }

    //重写equals方法，实现输入课程名称，相同即返回true,
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof Course)) {
            return false;
        }
        Course course = (Course) obj;
        if (this.getame() == null) {
            if (course.getame() == null) {
                return true;
            } else {
                return false;
            }
        } else {
            if (this.getame().equals(course.getame())) {
                return true;
            } else {
                return false;
            }
        }
    }

    //重写hashCode方法，实现课程名称相同，即返回true
    @Override
    public int hashCode() {
        final int prime=31;
        int result=1;
        result=prime*result+((name==null)? 0:name.hashCode());
        return result;
    }
}
